# Contributor: Sergei Lukin <sergej.lukin@gmail.com>
# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Michael Mason <ms13sp@gmail.com>
pkgname=tiff
pkgver=4.6.0
pkgrel=0
pkgdesc="Provides support for the Tag Image File Format or TIFF"
url="https://gitlab.com/libtiff/libtiff"
arch="all"
license="libtiff"
depends_dev="
	zlib-dev
	zstd-dev
	"
makedepends="
	$depends_dev
	cmake
	libjpeg-turbo-dev
	libwebp-dev
	python3
	samurai
	"
checkdepends="diffutils"
subpackages="$pkgname-doc $pkgname-dev $pkgname-tools libtiffxx"
source="https://download.osgeo.org/libtiff/tiff-$pkgver.tar.xz"

# secfixes:
#   4.5.0-r5:
#     - CVE-2023-0795
#     - CVE-2023-0796
#     - CVE-2023-0797
#     - CVE-2023-0798
#     - CVE-2023-0799
#     - CVE-2023-0800
#     - CVE-2023-0801
#     - CVE-2023-0802
#     - CVE-2023-0803
#     - CVE-2023-0804
#   4.5.0-r3:
#     - CVE-2022-48281
#   4.5.0-r0:
#     - CVE-2022-2953
#     - CVE-2022-3213
#     - CVE-2022-3570
#     - CVE-2022-3597
#     - CVE-2022-3598
#     - CVE-2022-3599
#     - CVE-2022-3626
#     - CVE-2022-3627
#     - CVE-2022-3970
#   4.4.0-r1:
#     - CVE-2022-2056
#     - CVE-2022-2057
#     - CVE-2022-2058
#     - CVE-2022-2519
#     - CVE-2022-2520
#     - CVE-2022-2521
#     - CVE-2022-34526
#   4.4.0-r0:
#     - CVE-2022-2867
#     - CVE-2022-2868
#     - CVE-2022-2869
#   4.3.0-r1:
#     - CVE-2022-0561
#     - CVE-2022-0562
#     - CVE-2022-0865
#     - CVE-2022-0891
#     - CVE-2022-0907
#     - CVE-2022-0908
#     - CVE-2022-0909
#     - CVE-2022-0924
#     - CVE-2022-22844
#     - CVE-2022-34266
#   4.2.0-r0:
#     - CVE-2020-35521
#     - CVE-2020-35522
#     - CVE-2020-35523
#     - CVE-2020-35524
#   4.1.0-r0:
#     - CVE-2019-6128
#   4.0.10-r2:
#     - CVE-2019-10927
#   4.0.10-r1:
#     - CVE-2019-14973
#   4.0.10-r0:
#     - CVE-2018-12900
#     - CVE-2018-18557
#     - CVE-2018-18661
#   4.0.9-r8:
#     - CVE-2018-10779
#     - CVE-2018-17100
#     - CVE-2018-17101
#   4.0.9-r6:
#     - CVE-2017-9935
#     - CVE-2017-11613
#     - CVE-2017-17095
#     - CVE-2018-10963
#   4.0.9-r5:
#     - CVE-2018-8905
#   4.0.9-r4:
#     - CVE-2018-7456
#   4.0.9-r2:
#     - CVE-2018-5784
#   4.0.9-r1:
#     - CVE-2017-18013
#   4.0.9-r0:
#     - CVE-2017-16231
#     - CVE-2017-16232
#   4.0.8-r1:
#     - CVE-2017-9936
#     - CVE-2017-10688
#   4.0.7-r2:
#     - CVE-2017-7592
#     - CVE-2017-7593
#     - CVE-2017-7594
#     - CVE-2017-7595
#     - CVE-2017-7596
#     - CVE-2017-7598
#     - CVE-2017-7601
#     - CVE-2017-7602
#   4.0.7-r1:
#     - CVE-2017-5225

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=MinSizeRel

	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure -j2
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

libtiffxx() {
	pkgdesc="C++ binding to libtiff"

	amove usr/lib/libtiffxx.so.*
}

tools() {
	pkgdesc="Command-line utility programs for manipulating TIFF files"

	amove usr/bin
}

sha512sums="
4cd9bb485bcac9c5efdd0c4814f2a38a762a3b69e70d909c05a24e2e9d2bd27357b9814e0cb1cee3898355d6ccfcf1615f715125c8ab8c651db474073734ab03  tiff-4.6.0.tar.xz
"
